import { Injectable } from '@nestjs/common';
import { RequestMap, RequestMapQuery } from 'my-ts-core/security';

import { RequestMapsRepository } from '@modules/request-maps/repositories/request-maps.repository';

@Injectable()
export class SecurityRequestMapQueryService implements RequestMapQuery {
  constructor(private readonly requestMapsRepository: RequestMapsRepository) {}

  async queryAll(): Promise<RequestMap> {
    const query = await this.requestMapsRepository.query();

    return query.map((item) => ({
      httpMethod: item.httpMethod,
      configAttribute: item.configAttribute,
      url: item.url,
    }));
  }
}
